Skip to content

fix(metrics): skip non-finite metric values in DatadogProvider (#8845) - #8846

Open
dhaiirryyaa wants to merge 1 commit into
aws-powertools:developfrom
dhaiirryyaa:fix/datadog-reject-non-finite-metrics
Open

dhaiirryyaa wants to merge 1 commit into
aws-powertools:developfrom
dhaiirryyaa:fix/datadog-reject-non-finite-metrics

Conversation

@dhaiirryyaa

Copy link
Copy Markdown
Contributor

Issue number: closes #8845

Summary

Changes

In aws_lambda_powertools/metrics/provider/datadog/datadog.py, add_metric now verifies math.isfinite(value) alongside the numbers.Real check. If value is non-finite (NaN, Infinity, or -Infinity), it issues a PowertoolsUserWarning and skips adding the metric to metric_set, matching the CloudWatch EMF provider behavior from #8797.

Also added documentation note in docs/core/metrics/datadog.md and regression tests covering nan, inf, and -inf in tests/functional/metrics/datadog/test_metrics_datadog.py.

User experience

Users adding non-finite metrics to DatadogMetrics will see a descriptive PowertoolsUserWarning instead of corrupting serialized metric logs with invalid JSON NaN/Infinity or causing downstream ingestion errors.

Verification

Ran pytest tests/functional/metrics/ and confirmed all 183 tests pass cleanly. Verified with ruff format --check and ruff check.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…owertools#8845)

Signed-off-by: dhairyakhandelwal880-dotcom <dhairyakhandelwal880@gmail.com>
@dhaiirryyaa
dhaiirryyaa requested a review from a team as a code owner November 16, 2026 17:56
@dhaiirryyaa
dhaiirryyaa requested a review from hjgraca November 16, 2026 17:56
@boring-cyborg boring-cyborg Bot added documentation Improvements or additions to documentation metrics tests labels Nov 16, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 16, 2026
@sonarqubecloud

Copy link
Copy Markdown

@dhaiirryyaa

Copy link
Copy Markdown
Contributor Author

Hi @leandrodamascena, friendly follow-up on this PR. It prevents NaN and infinite values from being emitted in DatadogProvider, resolving #8845. All unit tests and SonarQube checks are green. Please let me know if anything else is needed to merge. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation metrics size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: DatadogProvider accepts non-finite (NaN, Infinity) metric values

1 participant